import 'package:flutter/material.dart';
// import 'package:fluttertoast/fluttertoast.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../../components/Dialog.dart';

import '../widget/ButtonItem.dart';

class DialogDemo extends StatefulWidget {
  DialogDemo({Key key}) : super(key: key);
  @override
  _DialogDemoState createState() => _DialogDemoState();
}

class _DialogDemoState extends State<DialogDemo> {
  _alertDialog() async {
    var res = await showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text('标题'),
            content: Text('确定？'),
            actions: [
              ButtonItem(
                type: 1,
                content: Text('取消'),
                onPressed: () {
                  Navigator.pop(context, 'no');
                },
              ),
              ButtonItem(
                content: Text('确定'),
                onPressed: () {
                  Navigator.pop(context, 'ok');
                },
              )
            ],
          );
        });
    if (res == 'no' || res == null) {
      return print('点击了取消');
    }
    print('点击了确定');
  }

  _simpleDialog() async {
    var res = await showDialog(
        context: context,
        builder: (context) {
          return SimpleDialog(
            title: Text('请进行选择'),
            children: [
              SimpleDialogOption(
                child: Text('选项A'),
                onPressed: () {
                  Navigator.pop(context, "a");
                },
              ),
              Divider(),
              SimpleDialogOption(
                child: Text('选项B'),
                onPressed: () {
                  Navigator.pop(context, "b");
                },
              ),
              Divider(),
              SimpleDialogOption(
                child: Text('选项C'),
                onPressed: () {
                  Navigator.pop(context, "c");
                },
              ),
            ],
          );
        });
    print(res);
  }

  _showModelBottomSheet() async {
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return Container(
            height: 300,
            child: ListView(
              children: [
                ListTile(title: Text('选项A')),
                Divider(),
                ListTile(title: Text('选项B')),
                Divider(),
                ListTile(title: Text('选项C')),
                Divider(),
                ListTile(title: Text('选项D')),
                Divider(),
                ListTile(title: Text('选项E')),
                Divider(),
                ListTile(title: Text('选项F')),
              ],
            ),
          );
        });
  }

  _showToast1() {
    Fluttertoast.showToast(
        msg: "This is Center Short Toast",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
        backgroundColor: Colors.black38,
        textColor: Colors.white,
        fontSize: 16.0);

    print('object');
  }

  _showMyDialog() {
    showDialog(
        context: context,
        builder: (context) {
          return MyDialog();
        });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('DialogDemo'),
      ),
      body: Center(
          child: Column(
        children: [
          ButtonItem(
            content: Text(
              'alert',
            ),
            onPressed: _alertDialog,
          ),
          ButtonItem(
            content: Text(
              'simple',
            ),
            onPressed: _simpleDialog,
          ),
          ButtonItem(
            content: Text(
              'showModelBottomSheet',
            ),
            onPressed: _showModelBottomSheet,
          ),
          ButtonItem(
            content: Text(
              '_showToast1',
            ),
            onPressed: _showToast1,
          ),
          ButtonItem(
              content: Text(
                '_showMyDialog',
              ),
              onPressed: _showMyDialog),
        ],
      )),
    );
  }
}
